package com.lagou.edu.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.lagou.edu.config.SentinelHandlersClass;
import com.lagou.edu.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/code")
public class CodeController {

    @Autowired
    private CodeService codeService;

    @GetMapping("/create/{email}")
    @SentinelResource(value = "sendCodeToEmail",blockHandlerClass = SentinelHandlersClass.class,
    blockHandler = "handleException",fallbackClass = SentinelHandlersClass.class,fallback = "fallbackMethod")
    public String sendCodeToEmail(@PathVariable String email){
        boolean result = codeService.sendCodeToEmail(email);
        if(result) {
            return "success";
        }else{
            return "false";
        }

    }

}
